<template>
  <div class="mod-config">


    <el-row>
      <el-col span="9">
        <h2>拆迁工程展示</h2>
      </el-col>
      <el-col span="8">
        <el-form>
          <el-form-item label="房屋全部展示/展示未分配">
            <button @click="getHouseAll()">
              <el-switch v-model="dataHouse.isfenpei"></el-switch>
            </button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col span="7">
        <el-form :inline="true" :model="dataForm" :rule="dataRule">
          <el-form-item prop="key">
            <!--<el-input v-model="dataForm.key" placeholder="请输入要分配的项目编号" clearable></el-input>-->
            当前选择的项目编号
          </el-form-item>
          <el-form-item prop="key">
            <div style="width: 10px; height: 10px">
              <span>{{dataForm.key}}</span>
            </div>
            <!--<el-input v-model="dataForm.key" placeholder="请输入要分配的项目编号" clearable></el-input>-->

          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="commit()">分配</el-button>
          </el-form-item>
          <el-form-item>
            <el-button @click="getHouseAll() ;clear()">刷新</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-row>
      <el-col span="10">
        <el-table
          :data="dataList"
          border
          v-loading="dataListLoading"
          @selection-change="selectionChangeHandle"
          style="width: 100%;height:486px"
          max-height="1750">
          <el-table-column
            prop="id"
            header-align="center"
            align="center"
            label="项目编号">
          </el-table-column>
          <el-table-column
            prop="name"
            header-align="center"
            align="center"
            label="项目名称">
          </el-table-column>
          <el-table-column
            prop="familyNum"
            header-align="center"
            align="center"
            label="拆迁总户数">
          </el-table-column>
          <el-table-column
            prop="totalSqu"
            header-align="center"
            align="center"
            label="拆迁总面积">
          </el-table-column>
          <el-table-column
            prop="needHouse"
            header-align="center"
            align="center"
            label="补偿总面积">
          </el-table-column>
          <el-table-column
            label="操作"
            width="80">
            <template slot-scope="scope">
              <el-button
                @click.native.prevent="selectRow(scope.$index, tableData)"
                type="text"
                size="small">
                选择
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          :total="totalPage"
          layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </el-col>
      <el-col span="1">
        <span>&nbsp</span>

      </el-col>
      <el-col span="13">
        <el-table
          :data="dataLists"
          border
          v-loading="dataListLoadings"
          @selection-change="selectionChangeHandles"
          style="width: 100%;height:486px"
          max-height="1750">
          <el-table-column
            type="selection"
            header-align="center"
            align="center"
            width="50">
          </el-table-column>
          <el-table-column
            prop="id"
            header-align="center"
            align="center"
            label="房屋编号">
          </el-table-column>
          <el-table-column
            prop="huxing"
            header-align="center"
            align="center"
            label="户型">
          </el-table-column>
          <el-table-column
            prop="suqare"
            header-align="center"
            align="center"
            label="面积">
          </el-table-column>
          <el-table-column
            prop="xiaoqu"
            header-align="center"
            align="center"
            label="所属小区">
          </el-table-column>
          <el-table-column
            prop="dongId"
            header-align="center"
            align="center"
            label="楼栋号">
          </el-table-column>
          <el-table-column
            prop="houseNum"
            header-align="center"
            align="center"
            label="门牌号">
          </el-table-column>
          <el-table-column
            prop="projectId"
            header-align="center"
            align="center"
            label="所属项目">
          </el-table-column>

        </el-table>
        <el-pagination
          @size-change="sizeChangeHandles"
          @current-change="currentChangeHandles"
          :current-page="pageIndexs"
          :page-sizes="[10, 20, 50, 100,200,400]"
          :page-size="pageSizes"
          :total="totalPages"
          layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>
<script>
  export default {
    data () {
      return {
        dataForm: {
          key: undefined
        },
        dataHouse: {

          isfenpei: false,
          houseId: 0

        },
        //工程展示相关数据
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelection: [],
        //房源展示相关
        dataLists: [],
        pageIndexs: 1,
        pageSizes: 10,
        totalPages: 0,
        dataListLoadings: false,
        dataListSelections: undefined,
      }
    },
    activated () {
      this.getDataList()
      this.getHouseAll()
    },
    methods: {
      handleCurrentChange (val) {
        this.currentRow = val
      },
      test () {
      },
      /* sentWhat () {
         if (this.dataHouse.isfenpei) {
           this.getHouseAll()
         } else {
           this.dataLists = []
         }
       },*/
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/generator/project/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      getHouseAll () {
        this.dataListLoadings = true
        if (this.dataHouse.isfenpei) {
          this.$http({
            url: this.$http.adornUrl('/generator/house/listhasfenpei'),
            method: 'get',
            params: this.$http.adornParams({
              'page': this.pageIndexs,
              'limit': this.pageSizes,
              'key': this.dataForm.key
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataLists = data.page.list
              this.totalPages = data.page.totalCount
            } else {
              this.dataLists = []
              this.totalPages = 0
            }

            this.dataListLoadings = false

          })
        } else {
          this.$http({
            url: this.$http.adornUrl('/generator/house/list'),
            method: 'get',
            params: this.$http.adornParams({
              'page': this.pageIndexs,
              'limit': this.pageSizes,
              'key': this.dataForm.key
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataLists = data.page.list
              this.totalPages = data.page.totalCount
            } else {
              this.dataLists = []
              this.totalPages = 0
            }
            this.dataListLoadings = false
          })
          this.dataListLoadings = false
        }
      },
      //刷新页面
      clear () {
        this.dataForm.key = undefined
      },
      // 拆迁工程每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 房屋展示每页数
      sizeChangeHandles (val) {
        this.pageSizes = val
        this.pageIndexs = 1
        this.getHouseAll()
      },
      // 拆迁工程当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 房屋展示当前页
      currentChangeHandles (val) {
        this.pageIndexs = val
        this.getHouseAll()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelection = val
      },
      selectionChangeHandles (val) {
        this.dataListSelections = val
      },
      selectRow (index, row) {
        this.dataForm.key = this.dataList[index].id
        console.log(dataLists)
      },
      // 表单提交  这是没有进行定制的表单提交方法
      commit (formName) {
        let k = this.dataForm.key
        let rex = /^[0-9]*$/
        if (k && rex.test(k)) {

          if (this.dataListSelections != undefined && this.dataListSelections.length != 0) {
            this.$http({
              url: this.$http.adornUrl(`/diaobo/diaobo/diaobo`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataListSelections,
                'key': this.dataForm.key
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '分配成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.getHouseAll()
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          } else {
            const h = this.$createElement
            this.$notify({
              message: h('i', {style: 'color: red'}, '请至少选择一个房屋进行分配'),
              duration: 1000
            })
          }

        } else {
          const h = this.$createElement
          this.$notify({
            message: h('i', {style: 'color: red'}, '请正确选择工程'),
            duration: 1000
          })
        }
      },
      open2 () {

      },
      last () {
      }

    }

    // 新增 / 修改
    /*addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },*/
    // 删除
    /*  deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/generator/project/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },*/
  }
</script>
<style>
  button {
    border: 0;

    background-color: transparent;

    outline: none;
  }
</style>
